#region File Description
//-----------------------------------------------------------------------------
// MenuEntry.cs
//
// XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
#endregion

namespace BlueGameComponent
{
    /// <summary>
    /// Helper class represents a single entry in a TouchMenuScreen. By default this
    /// just draws the entry text string, but it can be customized to display menu
    /// entries in different ways. This also provides an event that will be raised
    /// when the menu entry is selected.
    /// </summary>
    public class TouchMenuEntry : MenuEntry
    {
        bool Pressed;
        Vector2 LastPressPosition;
        float MyScale;
        Color color;

        public TouchMenuEntry(string text)
            :base(text)
        {
            MyScale = 0.75f;
            this.color = Color.Black;
        }
        public TouchMenuEntry(string text,Color color)
            : base(text)
        {
            MyScale = 0.75f;
            this.color = color;
        }

        #region Update and Draw


        /// <summary>
        /// Updates the menu entry.
        /// </summary>
        public override void Update(MenuScreen screen, bool isSelected, GameTime gameTime)
        {
            bool _Pressed = false;

            TouchCollection collection = TouchPanel.GetState();
            if (collection.Count > 0)
            {
                TouchLocation touchLocation = collection[0];
                if (TouchLocationState.Moved == touchLocation.State)
                {
                    Point tapLocation = new Point((int)touchLocation.Position.X, (int)touchLocation.Position.Y);
                    if (screen.GetMenuEntryHitBounds(this).Contains(tapLocation))
                    {
                        _Pressed = true;
                        LastPressPosition = touchLocation.Position;
                    }
                }
            }
           // if()
            {
                Pressed = _Pressed;
            }
        }

        
        /// <summary>
        /// Draws the menu entry. This can be overridden to customize the appearance.
        /// </summary>
        public override void Draw(MenuScreen screen, bool isSelected, GameTime gameTime)
        {
            isSelected = false;
            if (Pressed)
            {
                // Draw the selected entry in yellow, otherwise white.
                Color Fontcolor = color;
                Color shadowColor = Color.Gray;

                // Pulsate the size of the selected menu entry.
                double time = gameTime.TotalGameTime.TotalSeconds;

                float pulsate = (float)Math.Sin(time * 6) + 1;

                float scale = 1 + pulsate * 0.05f * selectionFade;

                // Modify the alpha to fade text out during transitions.
                Fontcolor = new Color(color.R, color.G, color.B) * screen.TransitionAlpha;

                // Draw text, centered on the middle of each line.
                ScreenManager screenManager = screen.ScreenManager;
                SpriteBatch spriteBatch = screenManager.SpriteBatch;
                SpriteFont font = screen.Font;

                spriteBatch.DrawString(font, text, position + new Vector2(4, 4), shadowColor, 0, Vector2.Zero, scale * MyScale,
                    SpriteEffects.None, 0);
                spriteBatch.DrawString(font, text, position + new Vector2(3, 3), Fontcolor, 0, Vector2.Zero, scale * MyScale, SpriteEffects.None, 0);
            }
            else
            {
                // Draw the selected entry in yellow, otherwise white.
                Color Fontcolor = color;
                Color shadowColor = Color.Gray;

                // Pulsate the size of the selected menu entry.
                double time = gameTime.TotalGameTime.TotalSeconds;

                float pulsate = (float)Math.Sin(time * 6) + 1;

                float scale = 1 + pulsate * 0.05f * selectionFade;

                // Modify the alpha to fade text out during transitions.
                Fontcolor = new Color(color.R, color.G, color.B) * screen.TransitionAlpha;

                // Draw text, centered on the middle of each line.
                ScreenManager screenManager = screen.ScreenManager;
                SpriteBatch spriteBatch = screenManager.SpriteBatch;
                SpriteFont font = screen.Font;

                spriteBatch.DrawString(font, text, position + new Vector2(4, 4), shadowColor, 0, Vector2.Zero, scale * MyScale,
                    SpriteEffects.None, 0);
                spriteBatch.DrawString(font, text, position, Fontcolor, 0, Vector2.Zero, scale * MyScale, SpriteEffects.None, 0);
            }
        }
        public override int GetHeight(MenuScreen screen)
        {
            return (int)((float)base.GetHeight(screen) * MyScale);
        }

        /// <summary>
        /// Queries how wide the entry is, used for centering on the screen.
        /// </summary>
        public override int GetWidth(MenuScreen screen)
        {
            return (int)((float)base.GetWidth(screen) * MyScale);
        }

        #endregion
    }
}
